package fx.game.demo.common;

import fx.game.demo.layout.GameLayout;
import fx.game.demo.layout.HeadLayout;
import fx.game.demo.layout.MainLayout;
import javafx.geometry.Insets;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.VBox;

/**
 *
 * @author: datom
 *
 * @create: 2021/12/6 17:45
 *
 * @Deprecated 布局类管理
 *
 **/
public class LayoutManage {

    /**
     * 头部布局
     *
     */
    private static HeadLayout headLayout;

    /**
     * 游戏布局
     */
    private static GameLayout gameLayout;

    /**
     * 主页面布局
     */
    private static MainLayout mainLayout;

    /**
     * 游戏结束提示窗口布局
     */
    private static BorderPane gameOverTipsWindowLayout;

    public static HeadLayout getHeadLayout() {
        if(headLayout == null) {

            //构造方法已经添加Label
            headLayout = new HeadLayout();

            //添加重置按钮
            headLayout.add(ButtonManage.getResetButton(), 1, 0);

            //颜色表按钮
            headLayout.add(ButtonManage.getColorsButton(), 2, 0);

            //添加关于按钮
            headLayout.add(ButtonManage.getOpenAboutButton(), 3, 0);
        }
        return headLayout;
    }

    /**
     * @Author: datom
     * @Date: 2021/12/6 18:30
     *
     * @Description: 获取游戏布局
     *
     */
    public static GameLayout getGameLayout() {
        if(gameLayout == null) {
            gameLayout = new GameLayout();
            gameLayout.setFocusTraversable(true);
        }
        return gameLayout;
    }

    /**
     * @Author: datom
     * @Date: 2021/12/6 18:30
     *
     * @Description: 获取主页面布局
     *
     *
     */
    public static MainLayout getMainLayout() {
        if(mainLayout == null) {
            mainLayout = new MainLayout();

            mainLayout.setTop(getHeadLayout());

            //设置外边距
            BorderPane.setMargin(getHeadLayout(), new Insets(20, 10, 20, 10));

            mainLayout.setCenter(getGameLayout());
        }


        return mainLayout;
    }

    /**
     * @Author: datom
     * @Date: 2021/12/6 18:54
     *
     * @Description: 获取游戏结束提示窗口布局
     *
     */
    public static BorderPane getGameOverTipsWindowLayout() {
        if(gameOverTipsWindowLayout == null) {
            gameOverTipsWindowLayout = new BorderPane();

            //标签居中
            BorderPane labelBorderPane = new BorderPane();
            labelBorderPane.setCenter(LabelManage.getGameOverLabel());
            labelBorderPane.setPrefHeight(BaseMeta.GAME_OVER_TIPS_WINDOW_WIDTH
                    - ButtonManage.getConfirmButton().getHeight());

            //让按钮居中
            BorderPane buttonBorderPane = new BorderPane();
            buttonBorderPane.setCenter(ButtonManage.getConfirmButton());
            BorderPane.setMargin(ButtonManage.getConfirmButton(),
                    new Insets(0, 0, 10, 0));

            VBox vBox = new VBox();
            vBox.setPrefWidth(LabelManage.getGameOverLabel().getWidth());
            vBox.getChildren().addAll(labelBorderPane, buttonBorderPane);

            gameOverTipsWindowLayout.setCenter(vBox);
        }
        return gameOverTipsWindowLayout;
    }
    
    /**
     * @Author: datom 
     * @Date: 2021/12/6 22:55
     * 
     * @Description: 获取关于窗口布局内容
     *
     */
    public static BorderPane getAboutWindowLayout() {
        BorderPane borderPane = new BorderPane();

        VBox vBox = new VBox();

        //设置子节点间距
        vBox.setSpacing(10);

        vBox.setPrefWidth(400);
        vBox.setMinWidth(400);
        vBox.setMaxWidth(400);

        vBox.getChildren().add(LabelManage.getAboutLabel("如何玩："));
        vBox.getChildren().add(LabelManage.getAboutLabel(BaseMeta.ABOUT_TEXT));
        vBox.getChildren().add(LabelManage.getAboutLabel("码云："));
        vBox.getChildren().add(HyperlinkManage.getHyperlink("点我打开码云", BaseMeta.GITEE_LINK));
        vBox.getChildren().add(LabelManage.getAboutLabel("我的博客："));
        vBox.getChildren().add(HyperlinkManage.getHyperlink("打开链接", BaseMeta.BLOGS_LINK));

        borderPane.setCenter(vBox);

        //设置上外边距
        BorderPane.setMargin(vBox,
                new Insets(20, 0, 0, 0));

        return borderPane;
    }
}
